package midi.patterns;

import midi.IntervalOperations.interval;
import midi.patterns.OldMidiPattern;

@Deprecated
public class MidiPatternFactory {
	public static OldMidiPattern makeAscMajorScale(int baseNoteNumber, int velocity, long length){
		return makePatternsFromScaleArray(makeAscMajorScale(baseNoteNumber), velocity, length);
	}
	
	
	public static OldMidiPattern makePatternsFromIntervalArray(int intervals[], int baseNoteNumber, 
			int velocity, long length){
		return makePatternsFromScaleArray(applyIntervals(intervals, baseNoteNumber), velocity, length);
	}
	
	
	public static OldMidiPattern makePatternsFromRootedIntervalArray(interval intervals[], int baseNoteNumber,
			int velocity, long length){
		
		
		int noteArray[] = makeNoteArrayFromIntervals(intervals, baseNoteNumber);
		
		return makePatternsFromScaleArray(noteArray, velocity, length);
	}
	
	public static int[] makeNoteArrayFromIntervals(interval intervals[], int baseNoteNumber){
		int noteArray[] = new int[intervals.length];
		
		for (int i = 0; i < intervals.length; i++){
			noteArray[i] = baseNoteNumber + intervals[i].offset();
		}
		
		return noteArray;
	}
	
	
	public static OldMidiPattern makePatternsFromScaleArray(int[] noteArray, int velocity, long length){
		OldMidiPattern patterns[] = new OldMidiPattern[noteArray.length];
		
		for (int i = 0; i < noteArray.length; i++){
			patterns[i] = new OldMidiPattern(noteArray[i], velocity, length);
			if (i != 0){
				patterns[i - 1].setNext(patterns[i]);
			}
		}
		
		return patterns[0];
		
	}
	
	
	public static int[] makeAscMajorScale(int baseNoteNumber){
		int intervals[] = {0, 2, 2, 1, 2, 2, 2, 1};
		
		return applyIntervals(intervals, baseNoteNumber);
	}
	
	public static int[] makeAscHarmMinorScale(int baseNoteNumber){
		int intervals[] = {0, 2, 1, 2, 2, 1, 3, 1};
		
		return applyIntervals(intervals, baseNoteNumber);
	}
	
	public static int[] makeAscMelodicMinorScale(int baseNoteNumber){
		int intervals[] = {0, 2, 1, 2, 2, 2, 2, 1};

		return applyIntervals(intervals, baseNoteNumber);
	}
	
	public static int[] makeAscNaturalMinorScale(int baseNoteNumber){
		int intervals[] = {0, 2, 1, 2, 2, 1, 2, 2};
		
		return applyIntervals(intervals, baseNoteNumber);
	}
	
	public static int[] makeAscPentatonicScale1(int baseNoteNumber){
		int intervals[] = {0, 2, 3, 2, 2};
		
		return applyIntervals(intervals, baseNoteNumber);
	}
	
	public static int[] makeAscPentatonicScale2(int baseNoteNumber){
		int intervals[] = {0, 2, 2, 3, 2};
		
		return applyIntervals(intervals, baseNoteNumber);
	}
	
	
	
	
	public static int[] applyIntervals(int intervals[], int baseNoteNumber)
	{
		int result[] = new int[intervals.length];
		for (int i = 0; i < intervals.length; i++){
			baseNoteNumber += intervals[i];
			result[i] = baseNoteNumber;
		}
		
		return result;
	}
	/*
	public static int[] makeMelody1(int baseNoteNumber){
		int scale = new int [];
		int intervals[] = 
	}
	*/
}

